package com.java110.mall.shop.api;

import com.alibaba.fastjson.JSONObject;
import com.java110.dto.shop.ShopSettingKeyDto;
import com.java110.po.shop.ShopSettingKeyPo;
import com.java110.mall.shop.bmo.shopSettingKey.IDeleteShopSettingKeyBMO;
import com.java110.mall.shop.bmo.shopSettingKey.IGetShopSettingKeyBMO;
import com.java110.mall.shop.bmo.shopSettingKey.ISaveShopSettingKeyBMO;
import com.java110.mall.shop.bmo.shopSettingKey.IUpdateShopSettingKeyBMO;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/shopSettingKey")
public class ShopSettingKeyApi {

    @Autowired
    private ISaveShopSettingKeyBMO saveShopSettingKeyBMOImpl;
    @Autowired
    private IUpdateShopSettingKeyBMO updateShopSettingKeyBMOImpl;
    @Autowired
    private IDeleteShopSettingKeyBMO deleteShopSettingKeyBMOImpl;

    @Autowired
    private IGetShopSettingKeyBMO getShopSettingKeyBMOImpl;

    /**
     * 微信保存消息模板
     * @serviceCode /shopSettingKey/saveShopSettingKey
     * @path /app/shopSettingKey/saveShopSettingKey
     * @param reqJson
     * @return
     */
    @RequestMapping(value = "/saveShopSettingKey", method = RequestMethod.POST)
    public ResponseEntity<String> saveShopSettingKey(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "keyId", "请求报文中未包含keyId");
Assert.hasKeyAndValue(reqJson, "settingType", "请求报文中未包含settingType");
Assert.hasKeyAndValue(reqJson, "settingName", "请求报文中未包含settingName");
Assert.hasKeyAndValue(reqJson, "settingKey", "请求报文中未包含settingKey");


        ShopSettingKeyPo shopSettingKeyPo = BeanConvertUtil.covertBean(reqJson, ShopSettingKeyPo.class);
        return saveShopSettingKeyBMOImpl.save(shopSettingKeyPo);
    }

    /**
     * 微信修改消息模板
     * @serviceCode /shopSettingKey/updateShopSettingKey
     * @path /app/shopSettingKey/updateShopSettingKey
     * @param reqJson
     * @return
     */
    @RequestMapping(value = "/updateShopSettingKey", method = RequestMethod.POST)
    public ResponseEntity<String> updateShopSettingKey(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "keyId", "请求报文中未包含keyId");
Assert.hasKeyAndValue(reqJson, "settingType", "请求报文中未包含settingType");
Assert.hasKeyAndValue(reqJson, "settingName", "请求报文中未包含settingName");
Assert.hasKeyAndValue(reqJson, "settingKey", "请求报文中未包含settingKey");
Assert.hasKeyAndValue(reqJson, "keyId", "keyId不能为空");


        ShopSettingKeyPo shopSettingKeyPo = BeanConvertUtil.covertBean(reqJson, ShopSettingKeyPo.class);
        return updateShopSettingKeyBMOImpl.update(shopSettingKeyPo);
    }

    /**
     * 微信删除消息模板
     * @serviceCode /shopSettingKey/deleteShopSettingKey
     * @path /app/shopSettingKey/deleteShopSettingKey
     * @param reqJson
     * @return
     */
    @RequestMapping(value = "/deleteShopSettingKey", method = RequestMethod.POST)
    public ResponseEntity<String> deleteShopSettingKey(@RequestBody JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "caId", "caId不能为空");

        Assert.hasKeyAndValue(reqJson, "keyId", "keyId不能为空");


        ShopSettingKeyPo shopSettingKeyPo = BeanConvertUtil.covertBean(reqJson, ShopSettingKeyPo.class);
        return deleteShopSettingKeyBMOImpl.delete(shopSettingKeyPo);
    }

    /**
     * 微信删除消息模板
     * @serviceCode /shopSettingKey/queryShopSettingKey
     * @path /app/shopSettingKey/queryShopSettingKey
     * @return
     */
    @RequestMapping(value = "/queryShopSettingKey", method = RequestMethod.GET)
    public ResponseEntity<String> queryShopSettingKey(@RequestParam(value = "shopId", required = false) String shopId,
                                                      @RequestParam(value = "keyId", required = false) String keyId,
                                                      @RequestParam(value = "settingKey", required = false) String settingKey,
                                                      @RequestParam(value = "settingType", required = false) String settingType,
                                                      @RequestParam(value = "settingName", required = false) String settingName,
                                                      @RequestParam(value = "page") int page,
                                                      @RequestParam(value = "row") int row) {
        ShopSettingKeyDto shopSettingKeyDto = new ShopSettingKeyDto();
        shopSettingKeyDto.setPage(page);
        shopSettingKeyDto.setRow(row);
        shopSettingKeyDto.setShopId(shopId);
        shopSettingKeyDto.setKeyId(keyId);
        shopSettingKeyDto.setSettingKey(settingKey);
        shopSettingKeyDto.setSettingType(settingType);
        shopSettingKeyDto.setSettingName(settingName);
        return getShopSettingKeyBMOImpl.get(shopSettingKeyDto);
    }
}
